

var loginform;

initLoginForm = function() {



	var textfield = {xtype:'textfield'
							 ,fieldLabel:passwordLabel
							 ,id:'password'
							 , allowBlank:false
							 ,inputType:'password',
								 cls:"inputTxt",
								 enableKeyEvents: true,
								
                listeners: {
                    keypress: handleRuleKeypress
                }

							};
	 loginform = new  Ext.FormPanel({ 
		 //height:400
			//,
		 id:'tool1'
			,align:'center'
			 
							 
			,border:false,
				labelAlign: 'right',
				//bodyStyle : 'margin-left: auto; margin-right: auto; height:220px; background:url(images/login_bg.jpg) top center no-repeat; vertical-align:middle;width:450px; margin-top:10%; padding:10px 0px 0px 100px;',
				cls:'initformCls',
				//align : 'center',
				method : 'post',
				defaults : {
					anchor : '75%'
				},
				items : [
						{

							html : '<div id="login_top1">'
									+ '<span class="heading">' + loginLabel
									+ '</span>' 
							,
							//bodyStyle : 'margin-left: auto; margin-right: auto; vertical-align:top;padding:10px 0px 0px 0px;text-align:center;font-family:"Trebuchet MS ", Arial, Helvetica, sans-serif;font-size:15px;color: #990000;font-weight: bold;text-decoration:none; line-height:25px;',
							width:190	

						},

						 
							{
							 xtype:'textfield'
							 ,fieldLabel:usernameLabel
							 ,id:'username'
							 , allowBlank:false,
								 cls:"inputTxt"
							},textfield,{
								//buttonAlign:'center'
								
								//,
								buttons:[{text:'' ,iconCls:'loginbtnbg',




									
								handler:loginSubmit




								
								
								}]
							}
								]
						
			});
	
 


	//initLoadingMessage(loadingLabel);
	return loginform;
};

var loginSubmit = function(button, event)  {
	
	
	if(Ext.getCmp('tool1') != null){
		
	Ext.getCmp('tool1').getForm().submit(
	 {
			url : 'afterlogin.html',
			
			waitMsg : 'Validating User',
			method:'POST', 
			 success:function(){
	               
	                  showLoadingMessage(loadingLabel);
	                        window.location = 'home.html';
                  
	            },
	 
			failure : function(form, action) {
			
			
					Ext.onReady(function(){
				    Ext.Msg.show({
				      title:'',
				      msg: invalidUser,
				      icon : Ext.MessageBox.ERROR,
				      bodyStyle:'font-color:#ffffff',
				      buttons: Ext.MessageBox.OK
				    });
				});
				
			}

		});

	};
	
};
function handleRuleKeypress(a,b) {
	if (b.keyCode == b.ENTER)
  loginSubmit();
}
